var player;
var programTimerId;
var programTimes = 500;
var lastProcess = 0;
var buffTime = 3;
function play(data){ 
	
	showTvBox(data);
	
	player =   new playerMgr (data.mode);
	player.playEnd = playEnd;
	player.addPlayerTask(data.playUrl, "", "");
	
	seekPlayTime = 0;
	if(playTimeObj && playTimeObj[curData.id+'-'+curData.curUrlId]){
		seekPlayTime = parseInt(playTimeObj[curData.id+'-'+curData.curUrlId]);
		
	}
	
	programTimerId = setInterval("progress()",programTimes);
}


function showTvBox(data){
	var con = '';
	
	
	con +='<div class="tvTitle">'+curData.name+'</div>';
		
	con += '<div class="tvIcon"><img src="'+$.getImageUrl('../'+data.icon,'../images/default_m.png')+'"/></div>';
	con += '<div class="buffer" id="buffingPercent"></div>';

	var tvBox = document.getElementById('tvBox');
	tvBox.innerHTML = con;
	tvBox.style.display = 'block';
}

function hideBufferBox(){
	
	var tvBox = document.getElementById('tvBox');
	tvBox.style.display = 'none';
		
}

function progress(){
	
	var playerState = player.getPlayerState();
	if(playerState == 4 || playerState == 5){
		if(seekPlayTime > 0){
			player.seekPlay(seekPlayTime);
			seekPlayTime = 0;
		}
	}
	
	//播放器开始播放，隐藏进度条
	if(playerState==5 || playerState==6){
		var body = document.getElementsByTagName('body')[0];
		body.setAttribute("style","background: url();");
		clearInterval(programTimerId);
		programTimerId = null;
		hideBufferBox();	
	}//缓冲中
	else{
		var progress=player.getPlayerMax();//8000毫秒为100%	
		if(playerState==4 ){
			var body = document.getElementsByTagName('body')[0];
			body.setAttribute("style","background: url();");
		}
		
		var progress=player.getPlayerMax();//8000毫秒为100%	
		if(playerState==4 ){
			
			progress=Math.ceil(progress*100/(buffTime*1000 ))
		}else{
			progress=Math.ceil(progress*100/(buffTime*1000 + 5000));
		}
		if(progress<lastProcess){
			progress = lastProcess;
		}
		
		if(progress>100){
			progress=100;	
		}
		lastProcess = progress;
		
		var buffingPercent = document.getElementById('buffingPercent');
		buffingPercent.innerHTML = lastProcess + '%';
	}
}